package com.oriole.api;

import com.querydsl.jpa.impl.JPAQueryFactory;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import javax.persistence.EntityManager;

/**
 * Created by IntelliJ IDEA.
 *
 * @author doublelife
 * Date: 2020/7/01
 * Time: 11:10
 * @EnableJpaAuditing //在JPA操作中启用审计功能
 * @EntityScan("com.oriole.entity") // 用于扫描JPA实体类 @Entity
 * @ComponentScan(basePackages = "com.oriole.api.module.*.*") // 用于扫描@Controller @Service
 * @EnableJpaRepositories(basePackages = "com.oriole.api.module.*.mapper")  // 用于扫描Dao @Repository
 */
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableJpaAuditing
@EntityScan("com.oriole.entity")
public class ApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiApplication.class, args);
    }

    @ApiModelProperty("让Spring管理JPAQueryFactory")
    @Bean
    public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) {
        return new JPAQueryFactory(entityManager);
    }
}
